package core;

import utils.Utils;

public class Position
{
	private int id;
	private String parkingName;
	private String parkingRegion;
        private int carsCount;                                                  //Количество машин на данной парковке в данный момент
	private String queue;

	public Position(int _id,String _parkingName,String _parkingRegion)
	{
		id = _id;
		parkingName = _parkingName;
		parkingRegion = _parkingRegion;
                carsCount = 0;
                queue = "";
	}

        public Position(int _id)
        {
            id = _id;
            parkingName = "";
            parkingRegion = "";
            carsCount = 0;
            queue = "";
        }
	
	public Position(byte[] data)
	{
		byte[] temp;
		int index,size;
		index = 0;
		//id
		temp = new byte[4];
		for (int i=0;i<4;i++)
		{
			temp[i] = data[index++];
		}
		id = Utils.byteToInt(temp);
		//parkingName
		temp = new byte[4];
		for (int i=0;i<4;i++)
		{
			temp[i] = data[index++];
		}
		size = Utils.byteToInt(temp);
		temp = new byte[size];
		for (int i=0;i<size;i++)
		{
			temp[i] = data[index++];
		}
		parkingName = Utils.byteToString(temp);
		//parkingRegion
		temp = new byte[4];
		for (int i=0;i<4;i++)
		{
			temp[i] = data[index++];
		}
		size = Utils.byteToInt(temp);
		temp = new byte[size];
		for (int i=0;i<size;i++)
		{
			temp[i] = data[index++];
		}
		parkingRegion = Utils.byteToString(temp);
		carsCount = 0;
                //������ ������
		temp = null;
		System.gc();
	}

        public void setQueue(String newQueue)
        {
            queue = newQueue;
        }

        public String getQueue()
        {
            return queue;
        }

        public String getCarsCount()
        {
            return Integer.toString(carsCount);
        }

        public void setCarsCount(int newCount)
        {
            carsCount = newCount;
        }

	public int getId()
	{
		return id;
	}

        public void setParkingName(String value)
        {
            parkingName = value;
        }
        
	public String getParkingName()
	{
		return parkingName;
	}

        public void setParkingRegion(String value)
	{
            parkingRegion = value;
	}

	public String getParkingRegion()
	{
		return parkingRegion;
	}
	
	public byte[] toByte()
	{
		byte[] res,temp;
		int size,index;
		//���������� ������ ������
		size = 4  + Utils.getStringSize(parkingName) + Utils.getStringSize(parkingRegion);
		//������� ������
		res = new byte[size];
		//��������� ������
		index = 0;
		//id
		temp = Utils.int32ToByte(id);
		for (int i=0;i<temp.length;i++)
		{
			res[index++] = temp[i];
		}
		//parkingName
		temp = Utils.getStringByte(parkingName);
		for (int i=0;i<temp.length;i++)
		{
			res[index++] = temp[i];
		}
		//parkingRegion
		temp = Utils.getStringByte(parkingRegion);
		for (int i=0;i<temp.length;i++)
		{
			res[index++] = temp[i];
		}
		temp = null;
		System.gc();
		return res;
	}
}
